#include<bits/stdc++.h>
using namespace std;

int main()
{
    list<int> node;
    list<int>::iterator id[100010];
    int n,flag[100010]={0};
    scanf("%d",&n);
    node.push_front(1);
    id[1]=node.begin();

    for(int i = 2; i <= n; i++)
    {
        int k,p;
        scanf("%d %d",&k,&p);
        if(!p)
        {
            id[i]=node.insert(id[k],i);
        }else{
            list<int>::iterator it=id[k];
            it++;
            id[i]=node.insert(it,i);
        }
    }
    int m,x;
    cin >> m;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d",&x);
        if(!flag[x]){
            flag[x]=1;
            node.erase(id[x]);
        }
    }

    for(list<int>::iterator it = node.begin(); it != node.end(); ++it) {
        cout << *it << " ";
    }
    cout<<endl;
    return 0;
}

/*struct node{
    int flag=1;
    int id;
    node* next;
};
int main()
{
    int n,m;node *head,*prev,*now,*p;
    head=new node;head->id=1;head->next=NULL;
    now = head;
    scanf("%d %d",&n,&m);
    for(int i=2;i<=n;i++)
    {
        p=new node;p->id=i;p->next=NULL;
        now->next=p;
        now=p;
    }
    now->next=head;
    now=head;prev=head;
    while((n--)>1)
    {
        for(int i=1;i<m;i++)
        {
            prev=now;
            now=now->next;
        }
        cout<<now->id<<" ";
        prev->next=now->next;
        delete now;
        now=prev->next;
    }
    cout<<now->id<<endl;
    delete now;
    return 0;

}*/
